#!/bin/bash

> resultsI.txt
for files in {16k,100k,250k,500k,1M,2M,4M,8M}
do

grep insercao -A 3 $files.txt | grep \\. | grep user | sed 's/s//g' | cut -d " " -f 5 | cut -d 'm' -f 1 > userM.txt
grep insercao -A 3 $files.txt | grep \\. | grep user | sed 's/s//g' | cut -d " " -f 5 | cut -d 'm' -f 2 > userS.txt
paste userM.txt userS.txt > user.txt
> user2.txt
while read linha
do
	echo $linha | awk ' {total = $1*60 + $2} END {print total*1000}' >> user2.txt
done < user.txt
cat user2.txt | awk '{total = total + $1} END {print total/5} ' > user.txt


grep insercao -A 3 $files.txt | grep \\. | grep sys | sed 's/s//g' | cut -d " " -f 6 | cut -d 'm' -f 1 > sysM.txt
grep insercao -A 3 $files.txt | grep \\. | grep sys | sed 's/s//g' | cut -d " " -f 6 | cut -d 'm' -f 2 > sysS.txt
paste sysM.txt sysS.txt > sys.txt
> sys2.txt
while read linha
do
	echo $linha | awk ' {total = $1*60 + $2} END {print total*1000}' >> sys2.txt
done < sys.txt
cat sys2.txt | awk '{total = total + $1} END {print total/5} ' > sys.txt

u=$(cat user.txt)
s=$(cat sys.txt)
echo "$u $s" | awk '{total = $1 + $2; print total}' > usersys.txt
t=$(cat usersys.txt)

echo "$files $t" >> resultsI.txt

done







> resultsS.txt
for files in {16k,100k,250k,500k,1M,2M,4M,8M}
do

grep busca -A 3 $files.txt | grep \\. | grep user | sed 's/s//g' | cut -d " " -f 5 | cut -d 'm' -f 1 > userM.txt
grep busca -A 3 $files.txt | grep \\. | grep user | sed 's/s//g' | cut -d " " -f 5 | cut -d 'm' -f 2 > userS.txt
paste userM.txt userS.txt > user.txt
> user2.txt
while read linha
do
	echo $linha | awk ' {total = $1*60 + $2} END {print total*1000}' >> user2.txt
done < user.txt
cat user2.txt | awk '{total = total + $1} END {print total/5} ' > user.txt


grep busca -A 3 $files.txt | grep \\. | grep sys | sed 's/s//g' | cut -d " " -f 6 | cut -d 'm' -f 1 > sysM.txt
grep busca -A 3 $files.txt | grep \\. | grep sys | sed 's/s//g' | cut -d " " -f 6 | cut -d 'm' -f 2 > sysS.txt
paste sysM.txt sysS.txt > sys.txt
> sys2.txt
while read linha
do
	echo $linha | awk ' {total = $1*60 + $2} END {print total*1000}' >> sys2.txt
done < sys.txt
cat sys2.txt | awk '{total = total + $1} END {print total/5} ' > sys.txt

u=$(cat user.txt)
s=$(cat sys.txt)
echo "$u $s" | awk '{total = $1 + $2; print total}' > usersys.txt
t=$(cat usersys.txt)

echo "$files $t" >> resultsS.txt

done

rm user.txt user2.txt sys.txt sys2.txt userS.txt userM.txt sysS.txt sysM.txt usersys.txt
